package weaver.interfaces.hitech.duss.action.cgsq;

import com.sap.mw.jco.JCO;
import com.weaver.general.BaseBean;
import weaver.general.Util;
import weaver.interfaces.jjy.duss.util.SAPConnPool;

import java.util.HashMap;
import java.util.Map;

/**
 * @Title: ecology-9-demo
 * @Company: 泛微软件
 * @author: weaver.Dusongsong
 * @version: 1.0
 * @CreateDate: 2020-06-30
 * @Description: ${description}
 * @ModifyLog:
 **/

public class ZBPM_MATERIAL_LIST {
    public  Map execute(Map<String,String> map) {
        BaseBean baseBean = new BaseBean();
        SAPConnPool SAPConn = new SAPConnPool();
        JCO.Client myConnection = SAPConn.getConnection();
        JCO.Function bapi = SAPConn.excuteBapi("ZBPM_MATERIAL_LIST");
        JCO.ParameterList input = bapi.getImportParameterList();//输入参数和结构处理
        JCO.ParameterList inputtable = bapi.getTableParameterList();//输入表的处理
        //输入参数
        input.setValue(map.get("I_LIFNR"),"I_LIFNR");//供应商编号
        input.setValue(map.get("I_MATNR"),"I_MATNR");//SAP Code
        //执行函数
        myConnection.execute(bapi);
        JCO.ParameterList out = bapi.getExportParameterList();//输出参数和结构处理
        JCO.ParameterList Table00 = bapi.getTableParameterList();//输出表的处理

        //返回处理结果以及日志
        JCO.Table tabs = Table00.getTable("IT_MATNR");
        System.out.println("SPA_COUNTS:"+tabs.getNumRows());
        Map<String,String> resultMap =  new HashMap<>();
        String netpr = Util.null2String(tabs.getValue("NETPR"));    // 采购凭证中的净价(以凭证货币计)
        String mfrpn = Util.null2String(tabs.getValue("MFRPN"));    //制造商零件编号
        String stawn = Util.null2String(tabs.getValue("STAWN"));    //外贸的商品代码和进口代码
        String maktx = Util.null2String(tabs.getValue("MAKTX"));    //物料描述（短文本）
        String waers = Util.null2String(tabs.getValue("WAERS"));    //货币码
        resultMap.put("netpr",netpr);
        resultMap.put("mfrpn",mfrpn);
        resultMap.put("stawn",stawn);
        resultMap.put("maktx",maktx);
        resultMap.put("waers",waers);
        //返回处理结果以及日志
        JCO.releaseClient(myConnection);
        return resultMap;
    }

    public static void main(String[] args) {
        ZBPM_MATERIAL_LIST list = new ZBPM_MATERIAL_LIST();
        Map<String,String> map = new HashMap<>();
        map.put("I_LIFNR","110579");
        map.put("I_MATNR","SMAT01220");
        Map returnMap =  list.execute(map);
        System.out.println(returnMap.toString());
    }
}
